package com.cmnit.analysis.dao

import com.cmnit.analysis.common.{TDao, TSql}
import org.apache.log4j.Logger
import org.apache.spark.sql.DataFrame

class VehicleGantryDao extends TSql with TDao {
  private val logger: Logger = Logger.getLogger(this.getClass)

  /**
   * 获取来源数据
   */
  def gantryETCBill(sqlTime: String): DataFrame = {
    sparkSQL(
      "select " +
        "gantryType," +
        "mediaType," +
        "substr(transTime,1,10) transTime," +
        "gantryId," +
        "vehicleType, " +
        "originalflag," +
        "obutraderesult," +
        "traderesult " +
        "from " +
        "ods.ods_etc_gantryetcbill " +
        "where "
        + sqlTime
    )
  }

  /**
   * 获取入口数据
   */
  def gantryEntrance(): DataFrame = {
    sparkSQL(
      "select " +
        "gantryType," +
        "mediaType," +
        "transTime," +
        "gantryId," +
        "vehicleType " +
        "from temp_gantryetcbill " +
        "where " +
        "gantryType='1' " +
        "and originalflag='1' " +
        "and ((mediatype='1' and obutraderesult='0') or (mediatype='2' and traderesult='0')) "
    )
  }

  /**
   * 入口数据关联门架中间表，获取门架名称
   */
  def gantryEntranceBroadcast(): DataFrame = {
    sparkSQL(
      "select " +
        "t.*," +
        "nvl(tmp.gantryName,'null') gantryName " +
        "from temp_entrance t " +
        "left join " +
        "tmp_organization_gantry tmp " +
        "on t.gantryId = tmp.gantryId"
    )
  }

  /**
   * 门架入口收费信息（结果表）
   */
  def gantryEnBillInfo(): DataFrame = {
    sparkSQL(
      "select " +
        "count(*) as vehicleCount," +
        "vehicleType," +
        "gantryType," +
        "mediaType," +
        "transTime statisDay," +
        "gantryName," +
        "gantryId " +
        "from " +
        "temp_entranceinfo " +
        "group by vehicletype,mediaType,transTime,gantryType,gantryName,gantryId"
    )
  }
}
